<?php

class LineController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $lines = new Application_Model_DbTable_Lines();
		$this->view->line = $lines->fetchAll();
		
    }

    public function addlineAction()
    {
		$form = new Application_Form_Line();
		$form->submit->setLabel('Add');
		$this->view->form = $form;
		
		if ($this->getRequest()->isPost()) {
				$formData = $this->getRequest()->getPost();
			if ($form->isValid($formData)) {
					$lines = new Application_Model_DbTable_Lines();
					$lines->addLine($form->getValue('name'), $form->getValue('description'));
					$this->_helper->redirector('index');
			} 
				else {
					$form->populate($formData);
				}

		}
        
    }

    public function editlineAction()
    {
        $form = new Application_Form_Line();
		$form->submit->setLabel('Save');
		$this->view->form = $form;
		
		if ($this->getRequest()->isPost()) {
				$formData = $this->getRequest()->getPost();
			if ($form->isValid($formData)) {
					$lines = new Application_Model_DbTable_Lines();
					$lines->updateLine((int)$form->getValue('id'), $form->getValue('name'), $form->getValue('description'));
					$this->_helper->redirector('index');
			}
				else {
					$form->populate($formData);
				}
		}
			else {
				$id = $this->_getParam('id', null);
				if ($id != null) {
					$lines = new Application_Model_DbTable_Lines();
					$form->populate($lines->getLine($id));
				}
			}
	}

    public function deletelineAction()
    {
        if ($this->getRequest()->isPost()) {
				$del = $this->getRequest()->getPost('del');
			if ($del == 'Yes') {
					$lines = new Application_Model_DbTable_Lines();
					$lines->deleteLine($this->getRequest()->getPost('id'));
			}
				$this->_helper->redirector('index');
		} 
			else {
				$lines = new Application_Model_DbTable_Lines();
				$this->view->line = $lines->getLine($this->_getParam('id', null));
			}
    }



}






